package com.wufan.day02;

/**
 * 回形数格式方阵的实现
 * @author SongWufan
 * @date 2021/3/5 11:37
 */
public class ArrayTest6 {
    public static void main(String[] args) {
        int n = 7;
        int[][] arr = new int[n][n];
        //要显示的数据
        int count = 0;
        //x轴的最大下标
        int maxX = n - 1;
        //y轴的最大下标
        int maxY = n - 1;
        //x轴的最小下标
        int minX = 0;
        //y轴的最小下标
        int minY = 0;
        while (minX <= maxX){
            for (int x = minX; x <= maxX; x++){
                arr[minY][x] = ++count;
            }
            minY++;
            for (int y = minY; y <= maxY; y++){
                arr[y][maxX] = ++count;
            }
            maxX--;
            for (int x = maxX; x >= minX; x--){
                arr[maxY][x] = ++count;
            }
            maxY--;
            for (int y = maxY; y >= minY; y--){
                arr[y][minX] = ++count;
            }
            minX++;
        }

    }
}
